package com.example.demo.rest.account;

import com.example.demo.api.account.OauthApi;
import com.example.demo.bean.AccountWebTestInfo;
import com.example.demo.bean.Res;
import com.example.demo.bean.vo.RegisterInfo;
import com.example.demo.test.alc.AccountTestImpl;
import com.example.demo.util.UrlCompressUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class AlcController {

    @Autowired
    AccountTestImpl accountTestImpl;

    @PostMapping("/registration/registerAuth")
    public String registerAuth(@RequestParam String email) {
        String country = "us";
        String lang = "en";
        String returnUrl = UrlCompressUtils.dESencode(String.format("https://account.lenovo.com/%s/%s/login", country, lang));
        RegisterInfo registerInfo = new RegisterInfo();
        String name = email.substring(0, email.indexOf("@"));
        registerInfo.setEmail(email);
        registerInfo.setPassword("1q2w3e4r");
        registerInfo.setFirstName(name);
        registerInfo.setLastName(name);
        registerInfo.setReturnUrl(returnUrl);
        registerInfo.setCheckProfile(false);
        registerInfo.setCheckJoin(false);
        registerInfo.setClientId("43479a4c22d2ba94c535");
        registerInfo.setClientName("Gaming Community AU");
        registerInfo.setChildPrivacy(false);
        return oauthApi.registerAuth(country, lang, registerInfo);
    }

    @Autowired
    OauthApi oauthApi;

    @GetMapping("alcinfo")
    public Res<List<AccountWebTestInfo>> oauthInfo(@RequestParam String env) {
        Res<List<AccountWebTestInfo>> result = new Res<>();
        List<AccountWebTestInfo> accountWebTestInfos = new ArrayList<>();
        accountWebTestInfos.add(new AccountWebTestInfo("", "https://account.lenovo.com/us/en/"));
        accountWebTestInfos.add(new AccountWebTestInfo("", "https://account.lenovo.com/jp/ja/"));
        accountWebTestInfos.add(new AccountWebTestInfo("", "https://account.lenovo.com/de/de/"));
        accountWebTestInfos.add(new AccountWebTestInfo("", "https://account.lenovo.com/au/en/"));
        result.setData(accountWebTestInfos);
        return result;
    }
}
